#pragma once

#include <stddef.h>
#include "Singleton.h"
#include "BufBlock.h"

class CBufBlockMgr;
class CBufChunkMgr;

class CBufMgr : public CSingleton<CBufMgr>
{
    friend class CSingleton;

public:
    ~CBufMgr();
    void operator delete(void *ptr);

    CBufMgr(const CBufMgr &rhs) = delete;
    CBufMgr &operator=(const CBufMgr &rhs) = delete;
    CBufMgr &operator=(CBufMgr &&rhs) = delete;

public:
    bool Init();
    void Destroy();
    BufBlockNode *GetBlock();
    bool FreeBlock(BufBlockNode *pNode);

private:
    CBufMgr();
    void *operator new(size_t sz);

private:
    CBufChunkMgr *m_pChunks;
    CBufBlockMgr *m_pBlocks;
};
